package com.wechat.order.util.signature.test;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

import java.io.IOException;

/**
 * Created by zzy on 2018/1/1.
 */
@Slf4j
public class RestBase64 {

    private static String src="赵泽阳";

    private static String yz="asdaffgaszx123asfa=asd";
    public static void main(String[] args) throws IOException {
       //jdkBase64();
        bouncyCastleBase64();
    }

    public static void jdkBase64() throws IOException {
        BASE64Encoder encoder=new BASE64Encoder();
        String  encode=  encoder.encode(src.getBytes());

        log.info(encode);
        System.out.println(encode);

        BASE64Decoder decoder=new BASE64Decoder();
        byte[] decode=  decoder.decodeBuffer(encode);
        System.out.println(decode);
        System.out.println(new String(decode));
    }

    public static void commonsCodesBase64(){
        byte[] encodeBytes= Base64.encodeBase64(src.getBytes());
        System.out.println(new String(encodeBytes));

        byte[] decodeBytes= Base64.decodeBase64(encodeBytes);
        System.out.println(new String(decodeBytes));
    }

    public static void bouncyCastleBase64(){
        byte[] encodeBytes=  org.bouncycastle.util.encoders.Base64.encode((src+yz).getBytes());
        System.out.println(new String(encodeBytes));
        byte[] decodeBytes=org.bouncycastle.util.encoders.Base64.decode(encodeBytes);
        System.out.println(new String(decodeBytes));
    }
}
